<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/hpp_c1_c2.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<%@ include file="/common/meta.jsp" %>
<title>VTC - Holistic Programme Planning - HPP</title>
<%@ include file="/common/css_js.jsp"%>

<SCRIPT type="text/javascript">
	var iframeResize = function(){
		var targObj = self;
		//1.  取得iframe的对象
		var targWin = targObj.parent.document.getElementById("programmeIframe");
		//2.  取得本页面的显示数据对象
		var projectionTypeTable = document.getElementById("offeringCampusDiv");
		
		if(targWin != null) {
		
			//3, 下面是取数据表格高度,
			// 也可取本htm文档的高度 ： var HeightValue = targObj.document.body.scrollHeight
			var HeightValue = projectionTypeTable.scrollHeight+20;
			targWin.style.height = HeightValue + "px";
		}
		
	}
	
	var validator;

	$(document).ready(function() {
		iframeResize();
		validator=$("#offeringCampusForm").validate();
	});

	
	
	function clickBtn(action){
		switch(action){
		case "add":
			  $("#offeringCampusForm").attr("action", "offering-campus!add.action?no-decorate");
			  break;
		case "delete":
			  $("#offeringCampusForm").attr("action", "offering-campus!delete.action?no-decorate");
			  break;
		case "save":
			if(validator.form()){
			  $("#offeringCampusForm").attr("action", "offering-campus!save.action?no-decorate");
			  $("#offeringCampusForm").submit();
			}
			return;
		}
		
		$("#offeringCampusForm").submit();
	}
	
	function changeCampus(id, campusCode){
		
		$.ajax({
			url : "offering-campus!ajaxGetDepartByCumpus.action?no-decorate&campusCode="+campusCode,
			cache : true,
			dataType : "json",
			async : false,
			success : function(departments) {
				$("#"+id).empty();
				
				$.each(departments, function(i, department) {
					$("#"+id).append(
							"<option value='"+department.code+"'>" + department.desc + "</option>");
				})
			},
			error : function(data) {
				$("#errorMsgSpan").html(data);
			}
		});			
	}
</SCRIPT> 

</head>
<body style="background-color: transparent;">	
	<s:form name="offeringCampusForm" id="offeringCampusForm" 
	        action="offering-campus!save.action?no-decorate" method="post">  
    <s:hidden name="programmeId"></s:hidden>   
    
	<div class="sListBorder" id="offeringCampusDiv">
      <div class="sList">
      
        <table cellspacing="0" cellpadding="0" border="0" width="100%" class="sTable">
          <tbody><tr>
            <td class="sTh checkbox">
            	<input type="checkbox" name="" id="controlCheckbox" class="inputCheckbox"
            	       onclick="clickParent('controlCheckbox','campusIds')">
            </td>
            <td class="sTh">Offering Campus </td>
            <td class="sTh">Offering Unit </td>
            <td class="sTh">Operating Campus </td>
            <td class="sTh">Operating Unit</td>
          </tr>

          <s:if test="%{pageDomain!=null&&pageDomain.size()!=0}">
             <s:iterator value="pageDomain" var="campusDomain" status="st">
		          <tr class="sRow2">
		            <td class="sCell">
		            	<input type="checkbox" name="campusIds" id="campusIds" value="<s:property value='#campusDomain.offeringCampus.id'/>" class="inputCheckbox" /
		            	        onclick="clickChild('controlCheckbox','campusIds')">
		            	<input type="hidden" name="results[<s:property value='#st.index'/>].id" id="results_<s:property value='#st.index'/>_id"
		            	       value="<s:property value='#campusDomain.offeringCampus.id'/>" ></input>
		            </td>
		            <td class="sCell">
		            
            
	            	<select style="width:155px" name="results[<s:property value='#st.index'/>].campus" 
                            class="inputSelect required" onchange="changeCampus('offeringUnit_<s:property value='#st.index'/>',this.value)">
		                <s:iterator value="paramService.campusList" var="campuss">
		               		<option value="<s:property value='#campuss.code'/>" 
		               			<s:if test="#campusDomain.offeringCampus.campus==#campuss.code">selected="selected"</s:if>>
		               				<s:property value="#campuss.desc"/>
		               		</option>
		            	</s:iterator>
		            </select>
            
		            </td>		            
		            <td class="sCell">
		            	<select style="width:155px" name="results[<s:property value='#st.index'/>].offeringUnit"  id="offeringUnit_<s:property value='#st.index'/>"
                                class="inputSelect required">
			                
								<s:iterator value="#campusDomain.offeringDepartments" var="offeringDepartment">
									<option value="<s:property value='#offeringDepartment.code'/>"
											<s:if test="#campusDomain.offeringCampus.offeringUnit==#offeringDepartment.code">selected="selected"</s:if>>
												<s:property value='#offeringDepartment.desc'/>
									</option>
								</s:iterator>
		              </select>
		            </td>
		            <td class="sCell">
		            	<select style="width:155px" name="results[<s:property value='#st.index'/>].operatingCampus" 
                                class="inputSelect required" onchange="changeCampus('operating_<s:property value='#st.index'/>',this.value)">
			                <s:iterator value="paramService.campusList" var="campuss">
			               		<option value="<s:property value='#campuss.code'/>" 
			               			<s:if test="#campusDomain.offeringCampus.operatingCampus==#campuss.code">selected="selected"</s:if>>
			               		<s:property value="#campuss.desc"/></option>
			            	</s:iterator>
		              	</select>
		            </td>
		            <td class="sCell">
		            	<select style="width:155px" name="results[<s:property value='#st.index'/>].operatingUnit"   id="operating_<s:property value='#st.index'/>"
                                class="inputSelect required">
								
								<s:iterator value="#campusDomain.operatingDepartments" var="operatingDepartment">
									<option value="<s:property value='#operatingDepartment.code'/>" 
									        <s:if test="#campusDomain.offeringCampus.operatingUnit==#operatingDepartment.code">selected="selected"</s:if>>
										<s:property value='#operatingDepartment.desc'/>
									</option>
								</s:iterator>		              
		               </select>
		            </td>
		          </tr>             
             </s:iterator>
          </s:if>   
        </tbody>
        </table>
      </div>
      
      <div class="btnSet btnSetTypeA">
        <div class="left">
			<s:if test="canEdit">
		          <div class="button">
		            <div class="left">
		              <div class="right">
		                <input type="button" onclick="clickBtn('add')" value="Add" class="inputButton">
		              </div>
		            </div>
		          </div>
		          
		          <div class="button">
		            <div class="left">
		              <div class="right">
		                <input type="button" onclick="clickBtn('save')" value="Save Offering Campus" class="inputButton">
		              </div>
		            </div>
		          </div>
		          
		          <div class="button">
		            <div class="left">
		              <div class="right">
		                <input type="button" onclick="clickBtn('delete')" value="Delete" class="inputButton">
		              </div>
		            </div>
		          </div>
        	</s:if>  
         
        </div>
      </div>
    </div>
    
 </s:form> 
    	
</body>
</html>   